package com.cnhis.cloudhealth.clinical.hosdoctor.patientcost.bo;

import com.cnhis.cloudhealth.clinical.hosdoctor.patientcost.dao.PatientcostDao;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.utils.Page;
import com.cnhis.cloudhealth.commons.utils.StaticKeys;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * Created by xiezhenyuan on 2016/3/24.
 */
@Service
public class PatientcostBo {
    @Resource
    private PatientcostDao patientcostDao;

    private ModelVo packModelVoPage(String nid,Map map,int pageno,int pagesize) {
        ModelVo mo = new ModelVo();
        try {
            Page p = patientcostDao.queryForPage(nid, map, pageno, pagesize);
            if (p.getList() != null && p.getList().size() > 0) {
                mo.setList(p.getList());
                mo.setResult(StaticKeys.OH_SUCCESS);
                mo.setTotal(p.getTotalNumber());
                mo.setRows(p.getList());
                mo.setPage(pageno);
                mo.setRecords(p.getTotalNumber());
                mo.setTotalPage(p.getTotalPage());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mo;
    }

    private ModelVo packModelVo(String nid,Map map){
        ModelVo mo = new ModelVo();
        List<Map<String,String>> list = null;
        try {
            list = patientcostDao.queryForList(nid,map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(list!=null&&list.size()>0) {

            mo.setList(list);
            mo.setResult(StaticKeys.OH_SUCCESS);
            mo.setTotal(list.size());
        }
        return mo;
    }

    public ModelVo selectIshavefee(Map map){return packModelVo("Patientcost.3",map);}

    public ModelVo selectFeelist(Map map,int pageno,int pagesize){
        Integer l = null;
        try {
            l = (Integer)patientcostDao.queryToObject("Patientcost.feelist_001",map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(l==null){
            l=2;
        }
        if(l<=4){
            return packModelVoPage("Patientcost.feelist_002",map,pageno,pagesize);
        }else{
            return packModelVoPage("Patientcost.feelist_003",map,pageno,pagesize);
        }
    }

    public ModelVo selectFeedepdetail(Map map){
        Integer l = null;
        try {
            l = (Integer)patientcostDao.queryToObject("Patientcost.feelist_001",map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(l==null){
            l=2;
        }
        if(l<=4){
            return packModelVo("Patientcost.929_001",map);
        }else{
            return packModelVo("Patientcost.929_002",map);
        }
    }
    public ModelVo selectFeeprosummary(Map map){
        Integer l = null;
        try {
            l = (Integer)patientcostDao.queryToObject("Patientcost.feelist_001",map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(l==null){
            l=2;
        }
        if(l<=4){
            return packModelVo("Patientcost.940_001",map);
        }else{
            return packModelVo("Patientcost.940_002",map);
        }
    }

    public ModelVo selectFeecatsummary(Map map){
        Long l = null;
        try {
            l = (Long)patientcostDao.queryToObject("Patientcost.feelist_001",map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(l==null){
            l=2l;
        }
        if(l<=4l){
            return packModelVo("Patientcost.943_001",map);
        }else{
            return packModelVo("Patientcost.943_002",map);
        }
    }

    public ModelVo selectFeemonsummary(Map map){
        Long l = null;
        try {
            l = (Long)patientcostDao.queryToObject("Patientcost.feelist_001",map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(l==null){
            l=2l;
        }
        if(l<=4l){
            return packModelVo("Patientcost.944_001",map);
        }else{
            return packModelVo("Patientcost.944_002",map);
        }
    }
    public ModelVo selectFeedaybillsummary(Map map){
        Long l = null;
        try {
            l = (Long)patientcostDao.queryToObject("Patientcost.feelist_001",map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(l==null){
            l=2l;
        }
        if(l<=4l){
            return packModelVo("Patientcost.946_001",map);
        }else{
            return packModelVo("Patientcost.946_002",map);
        }
    }
    public ModelVo selectFeedaycatsummary(Map map){
        Integer l = null;
        try {
            l = (Integer)patientcostDao.queryToObject("Patientcost.feelist_001",map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(l==null){
            l=2;
        }
        if(l<=4){
            return packModelVo("Patientcost.948_001",map);
        }else{
            return packModelVo("Patientcost.948_002",map);
        }
    }

    public ModelVo selectReminder(Map<String,Object> map,int pageno,int pagesize){return packModelVoPage("Patientcost.2129",map,pageno,pagesize);}
}
